package com.globallogic.training.javase.basics;

import java.util.Scanner;
import java.util.Arrays;

/**
* The console application testing if two provided strings are anagrams.
*
* @version 0.1
* @author Artem.Zeltinsh
*/
public class AnagramChecker
{
	private static final String WELCOME_MESSAGE = 
			"# The console application testing if two provided strings are anagrams.\n";

	private static final String FIRST_PROMPT_MESSAGE = "Please input the 1st string: ";
	
	private static final String SECOND_PROMPT_MESSAGE = "Please input the 2nd string: ";
	
	private static final String OUTPUT_MESSAGE_FORMAT = "Is anagram: %b";

	public static void main(String[] args)
    {
        System.out.println(WELCOME_MESSAGE);

        Scanner in = new Scanner(System.in);

        System.out.print(FIRST_PROMPT_MESSAGE);
        String firstString = in.nextLine();

        System.out.print(SECOND_PROMPT_MESSAGE);
        String secondString = in.nextLine();

        char[] firstArray = firstString.toLowerCase().replaceAll("\\s", "").toCharArray();
        char[] secondArray = secondString.toLowerCase().replaceAll("\\s", "").toCharArray();

        Arrays.sort(firstArray);
        Arrays.sort(secondArray);

        boolean isAnagram = Arrays.equals(firstArray, secondArray);
        System.out.printf(OUTPUT_MESSAGE_FORMAT, isAnagram);
    }
} 
